// Town script for town 4: Pilgrim's rest

begintownscript;

variables;
int choice;
int i,index,dist,best_dist;
int zombie;

body;

beginstate INIT_STATE;
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
if (get_flag(4,0) == 1) {
		if (get_ran(1,1,8) == 8)
				play_sound(44);

		if (get_ran(1,1,8) == 8)
				play_sound(119);
		}

if(get_flag(4,2)==0) {
	message_dialog("The closer we get to the center of town, the more unnerving everything gets. The silence still persists and it's more oppressive than ever.","");
	set_flag(4,2,1);
	}

// Next follows a chunk of code to coordinate the zombies
if (get_flag(250,0) < get_flag(4,20)) {
		zombie = get_ran(1,234,236); // determine the zombie to place

		i = 0;

		best_dist = 10000; // set variable to impossible distance, so that whatever happens, we'll always get results smaller

		while (i < 5) { // loop over all flags now
			dist = group_dist_to_loc(0,get_flag(200,i),get_flag(201,i));

			if (dist < best_dist){
					best_dist = dist; // if dist is smaller than best distance, make our new best distance the distance to be used in the next run
					index = i; // store i for later use
					}
			i = i + 1;
			}
		place_monster(get_flag(200,index),get_flag(201,index),zombie,0); // now spawn the monster at the location ((200,index),(201,index)), where index is from 0 to 4
		inc_flag(250,0,1); // add one to the amount of zombies that should be roaming the streets
		}
break;

beginstate 10;
if (get_flag(4,0) == 1) {
		message_dialog("Going there would be idiotic. No, we must stay in this part of town. We already saw what happened with the people that fled that way: they ended up being killed at the town hall.","We must stay here and look for the stairs up to the roofs.");
		end();
		}

		move_to_new_town(3,11,43);

message_dialog("We can only go on when we have regrouped and are not fighting, so let's do that first.","");
block_entry(1);
break;

beginstate 11;
if (is_combat() == 1) {
		message_dialog("We can only go on when we have regrouped and are not fighting, so let's do that first.","");
		block_entry(1);
		end();
		}

if (get_flag(4,0) == 0) { // zombies not chasing
		message_dialog("This stairs go to the roof, most probably. We don't have any real business there, so let's just stay downstairs for now.","");
		set_flag(4,1,1);
		block_entry(1);
		}

if (get_flag(4,0) == 1) {
		reset_dialog();
		add_dialog_str(0,"Are we sure we want to go up?",0);
		add_dialog_choice(0,"Yes, let's go up.");
		add_dialog_choice(1,"No, let's stay down.");
		choice = run_dialog(1);
		
		if (choice == 1)
				move_to_new_town(5,34,10);
		}
break;

beginstate 12;
if(get_flag(4,3)==0){
	message_dialog("Whatever came past here, it didn't like alleys. It sort of went right through the walls in much the same way as it barged through the barricades we passed earlier. Another example of its strength.","As we look up into the gloomy night sky, we ponder what happened here. What could have chased all these people to a certain death, but without leaving any bodies? Remarkable, yet frightening.");
	set_flag(4,3,1);
	}
break;

beginstate 13;
if(get_flag(4,4)==0){
	message_dialog("From the dark alley, we emerge into a bigger, broader street. The scent of blood is starting to overpower us and we get an urge to vomit. The sooner we get out of this place the better.","");
	set_flag(4,4,1);
	}
break;

beginstate 14;
if(get_flag(4,5)==0 && get_flag(4,0) == 0){
	message_dialog("Another barricade here. Teeth and claw marks all over it, generally on the other side of the barricade. Though we don't know what made them, we can guess it came from the square on the other side of this barricade.","");
	set_flag(4,5,1);
	}
break;

beginstate 15;
if(get_flag(4,6)==0){
	message_dialog("It looks as though the owners of this place did a timely runner. There is some trash here and there, but cobwebs and dust is what mainly dominates this place.","Wise decision on their side to leave.");
	set_flag(4,6,1);
	}
break;

beginstate 16;
if(get_flag(4,7)==0){
	message_dialog("These must be the barracks for the local militia. Soms walls seem to have collapsed, but most of the building is still standing. Some blood here and there, but not much. The fighting must have been mostly in the streets.","");
	set_flag(4,7,1);
	}
break;

beginstate 17;
message_dialog("Not a lot is written on this message board, except the names of the hanged men over there, and what the church has been doing lately. Not very interesting.","");
break;

beginstate 18;
if(get_flag(4,8)==0){
	message_dialog("There are several hanged bodies here, two of them are already reduced to skeletons that are only barely being kept together by the remaining tissue, but one actually still is a corpse.","The corpse doesn't look quite like a normal corpse. Something about the skin, the eyes. It doesn't quite fit the standard corpses we normally come across.");
	set_flag(4,8,1);
	}
break;

beginstate 19;
if(get_flag(4,9)==0){
	message_dialog("Apparently, the beasts didn't quite agree with what probably was a barricade. There are crumbled stones everywhere and also the surrounding houses have not stayed completely undamaged.","The more we progress through this mystery-shrouded city, the more unnerving it all gets. The oppressive silence, combined with all the blood and gore we come across doesn't bode well for the future. We should tread carefully.");
	set_flag(4,9,1);
	}
break;

beginstate 20;
if(get_flag(4,10)==0){
	reset_dialog();
	add_dialog_str(0,"This barricade was attacked from the other side. There are a lot of nail marks, and some boulders must have been pulverized before their attention was directed to something else. Clearly, they started attacking but stopped soon after.",0);
	if (get_flag(4,9) == 1)
			add_dialog_str(1,"As we already have seen, they found another, quicker to destroy way.",0);
	add_dialog_choice(0,"Okay");
	run_dialog(1);
	set_flag(4,10,1);
	}
break;

beginstate 21;
if(get_flag(4,11)==0){
	message_dialog("After tracking through this pit of carnage, this hellish place of blood and pain, this managed to stand out. The brutality and force that must have come with what happened here was astonishing. Everything, including rubble, is soaked with blood.","One of the buildings has partially collapsed. A lot of walls have tumbled down together with the roof. The building seems to be fairly big. Anyway, the blood trail leads us inside.");
	set_flag(4,11,1);
	}
break;

beginstate 22;
if(get_flag(4,12)==0){
	reset_dialog();
	add_dialog_str(0,"It's because not all of the floor is actually covered that we know that this building's floor is built with stone tiles, for you'd say that the floor was covered with a red carpet. The blood is everywhere and the stench of decay is horrendous.",0);
	if (get_flag(4,14) == 0)
		add_dialog_str(1,"Staring into the darkness that is the interior of this building, we'd much rather go elsewhere. Maybe that's what we should do. We'll come back once we find a good reason to go in. The square might have some buildings that are worth looking at.",0);
	choice = run_dialog(1);
	set_flag(4,12,1);
	}
break;

beginstate 23;
reset_dialog();
add_dialog_str(0,"We search the shelves, and soon find something of interest. It seems to be an old record of the HMC, about the project to be titled _HIM_.",0);
add_dialog_str(1,"_As the HMC is growing, it becomes a difficult to maintain plant. Everywhere there is business, everywhere things are happening and we simply don't have the kind of manpower to efficiently record everything that is happening.",20);
add_dialog_str(2,"_No powerful enough human being on the planet would ever want to do such mundane jobs as closing and opening doors, recording what comes in and out and maintaining a pleasant atmosphere. It is apparent we need something bigger than a human being._",20);
add_dialog_str(3,"We read on, until we come to another interesting bit:",0);
add_dialog_str(4,"_We decided on a half organic, half machine being. It will be titled HIM: Human Intelligence Machine, and it will do all tasks necessary to maintain our big plant. Planning and testing will be in the hands of Mister Conrad and John.",20);
add_dialog_str(5,"Thus this scroll ends. We know what happened afterwards, how it all went wrong.",0);
add_dialog_choice(0,"Let us go again.");
choice = run_dialog(1);
break;

beginstate 24;
if(get_flag(4,13)==0){
	message_dialog("What luck! If we can believe what the sign says, this must be the local HMC office. There seem to be some bookshelves still in there with scrolls in them. They might be worth a look.","");
	set_flag(4,13,1);
	}
break;

beginstate 25;
reset_dialog();
add_dialog_str(0,"We search the shelves, and soon find something of interest. It seems to be an old record of the HMC, about the project to be titled _HIM_.",0);
add_dialog_str(1,"_There are problems with HIM, it appears. During some test, HIM's mind got damaged. John informed us of something called _morality failure_, but didn't quite tell us what it does. Anyway, HIM has been terrorising the workers a bit._",20);
add_dialog_str(2,"_Haven't been there myself, but inside sources confirm this: Trapping in small rooms, trapping in the lower mines, causing small explosions._",20);
add_dialog_str(3,"_Now, the trapping of people is relatively innocent, but the explosions can be dangerous. The  toxic canisters we use to get rid of all kinds of vermin could get damaged. The toxic gas in it might escape and infect human beings, with nasty consequences._",20);
add_dialog_str(4,"Is that what happened then? Mine workers got infected with the poison and brought it back home? They then died at home, possibly infecting their relatives. Relatives then poisoned others. In no time, the town would have been infected, ill, or dead.",0);
add_dialog_str(5,"It doesn't really account for the struggles and the brutality of force that we saw in these streets, but it does account for the disappearance of all the townspeople.",0);
add_dialog_choice(0,"Let us go again.");
choice = run_dialog(1);

message_dialog("If we want to know more, our best guess is to go to the hospital, which, if we are right, is the place where the bloodtrail led us.","");
set_flag(4,14,1);
break;

beginstate 26;
if(get_flag(4,14)==0){
	message_dialog("Really, it'd be better to leave this grim building until we know for sure we can find information inside.","Maybe there's a store on the square to the north that'll help us.");
	block_entry(1);
	}
break;

beginstate 27;
if(get_flag(4,15)==0){
	message_dialog("That road to the west, that'll be the entryway to the church. Pity it's blocked, since the church seems to be quite beautiful, viewing it from here. Inside it probably isn't much better than what we have seen here. Filled with decay and all that.","");
	set_flag(4,15,1);
}
break;

beginstate 28;
if(get_flag(4,16)==0){
	message_dialog("This house has been left remarkably undamaged. Not even a spot of blood. There is a bit of trash and dust on the floor, but that's not really surprising. What is surprising is that in the midst of this carnage, it hasn't sustained any real damage.","What's more, it seems there are some items lying around. There might be something useful to take.");
	set_flag(4,16,1);
}
break;

beginstate 29;
if(get_flag(4,17)==0){
	message_dialog("It's indeed a hospital in here. The floor and arrangement of the hall to the south betrays the building's purpose. There is rubble everywhere and the amounts of blood are enormous.","Hm. What a grim sight this is. We'd be happy if we could go away. Meanwhile, the silence is still there. A deafening silence almost. Let's try and find the information we need and piss off.");
	set_flag(4,17,1);
}
break;

beginstate 30;
if (get_flag(4,0) == 1)
		message_dialog("No, we can't stay here and read more reports and such nonsense. We have to run, RUN!","");

if (get_flag(4,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"We rummage through the desk of one of the doctors of this hospital. Most papers we come across appear to be budget related stuff and diagnosis reports that are of mild interest to us. However, soon we hit a journal:",0);
		add_dialog_str(1,"_New patients came in today. Interestingly, two mine workers with just about the same symptoms. Seems to be some sort of poisoning. HMC was evacuated today. Link?_",20);
		add_dialog_str(2,"The following few pages describe their symptoms, mostly headache and stomach ache. A bit onwards a new status report on the patients:",0);
		add_dialog_str(3,"_This is getting a bit out of hand. More mine workers came in, including some of their relatives that apparently stayed at home to care for them. All of them have the same symptoms. They feel ill, miserable, some have spots on their skins._",20);
		add_dialog_choice(0,"Turn the page.");
		choice = run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"_All beds are taken, still more patients. We don't have the capacity for this! A spreading disease, probably caused by a toxin from the HMC. A lot of mine workers have it, estimates are that a quarter of town got infected._",20);
		add_dialog_str(1,"More of this on the following pages. We skim through it and start reading again after a few pages:",0);
		add_dialog_str(2,"_This can't be, never seen something like it: the toxin is causing the people to mutate? Their skin looks deathly and their eyes turn either yellow or red. Speech affected: they growl rather than speak. What is this?!_",20);
		add_dialog_str(3,"The doctor himself might be getting infected at this point. The handwriting starts to look really bad, and it's not improving. It gets worse with every sentence, making it hard to read.",0);
		add_dialog_str(4,"_Cant rite wel. Am infectet to maybe. Skin pale, eyes discolered, must hav help and hav help soon, geting worse._",20);
		add_dialog_str(5,"The report continues, but the handwriting is so bad, that we can't really read it. Even if we could, the sentences are garbled, full of spelling mistakes and grammatical errors. Strangely, the doctor describes something we have seen before...",0);
		add_dialog_choice(0,"Okay");
		choice = run_dialog(1);

		if (get_flag(210,1) != 0 || get_flag(210,2) != 0 || get_flag(210,3) != 0 || get_flag(210,4) != 4)
				message_dialog("This disease business is worrying, particularly since we are feeling ill too right now. What if the disease is affecting us? We sure have to get out of this place before the disease gets us too.","");

		run_animation_sound(44);
		pause(10);

		message_dialog("What.. what was that...?","All this silence, the utter, deafening oppressive silence. Surely, that wasn't a sound? Probably just our ears taking a spin with our thoughts.");

		pause(10);
		run_animation_sound(119);
		pause(10);

		reset_dialog();
		add_dialog_str(0,"Could it be... No, the streets were completely empty just a while ago. Surely they will be empty now too? Unless they were waiting for us. Silent as the lion, waiting for his prey to be exactly there where it can't move.",0);
		add_dialog_str(1,"The mutation the doctor described; the ones falling for the toxin didn't die. They lived. As undead. Not dead, not alive, somewhere in between, ready to feed upon whoever comes here.",0);
		add_dialog_str(2,"We must go. We are still alive and are a lot faster than the zombies: slow, waggling monsters. We have to leave, we have to run immediately! But where...",0);
		add_dialog_choice(0,"Erm..");
		choice = run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"There might be just one building that is not infected, where the zombies have not been yet: the church.",0);
		add_dialog_str(1,"Problem though: the entrance is blocked, we saw all the rubble. Running straight towards it is no option.",0);
		add_dialog_str(2,"We have to find another route. We can't go through the fence, nor around it. Digging a tunnel would take far too long. So, we should go over it...",0);
		add_dialog_str(3,"The roofs! We go over the roofs! Let's hope the zombies won't be following us over the roofs. It's our best bet and we have no time to lose. We have to find stairs to go to the roof, quickly!",0);
		if (get_flag(4,1) == 1)
				add_dialog_str(4,"Stairs, stairs... Wait a sec, the militia. We were there, we found stairs! We should go there and take the stairs up. Now we must run.",0);
		add_dialog_choice(0,"RUN");
		choice = run_dialog(1);

		set_flag(4,0,1); // zombies start chase
		}
break;

beginstate 31;
if(get_flag(4,18)==0){
	message_dialog("These poor souls. They went into this room when they saw their enemies, and locked the door. They never came out.","");
	set_flag(4,18,1);
	}
break;

beginstate 32;
if(get_flag(4,19)==0){
	message_dialog("People blocked off the way to the next part of town. A wise decision, since the beasts found other victims and left the other parts of town sort of untouched.","Well, probably. We can't be too sure of it.");
	set_flag(4,19,1);
}
break;

beginstate 33;
if (get_flag(4,20) < 6 && get_flag(4,0) == 1) {
		inc_flag(250,0,2); // adjust amount of zombies in town
		activate_hidden_group(2);
		set_flag(4,20,6);
		message_dialog("As we continue through this street, we hear a deep grumble behind us. We look, and stare into the ugly faces of two more zombies.","");
		}
break;

beginstate 34;
if (get_flag(4,20) < 8 && get_flag(4,0) == 1) {
		inc_flag(250,0,2); // adjust amount of zombies in town
		activate_hidden_group(3);
		set_flag(4,20,8);
		message_dialog("As we continue through this street, we hear a deep grumble to our left. We look, and stare into the ugly faces of two more zombies.","");
		}
break;

beginstate 35;
if (get_flag(4,21) == 0 && get_flag(4,0) == 1) {
		message_dialog("We walk out into the rubble-filled streets. As we do that, we hear murmling and gurgling, and are confronted with the foul-smelling bodies of several zombies.","");
		activate_hidden_group(1);
		set_flag(4,20,4); // max amount of zombies is 4
		inc_flag(250,0,4); // adjust amount of zombies in town
		set_flag(4,21,1);
		}
break;

beginstate 36;
if(get_flag(4,4)==0){
	message_dialog("From the restaurant, we emerge into a bigger, broader street. The scent of blood is starting to overpower us and we get an urge to vomit. The sooner we get out of this place the better.","");
	set_flag(4,4,1);
	}
break;